/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package spasticinvadoors;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.JComponent;

/**
 *
 * @author Bertil
 */
public class Sprite extends JComponent{
    Position position;

    

    String type;

    int velocity;
    BufferedImage image;
    String imageName = "";
    public Sprite(String t_in, int x, int y, int v_in){
        position = new Position(x, y);
        velocity = v_in;
        type = t_in;

        if(t_in.equals("Alien") || t_in.equals("Shield") || t_in.equals("Bullet") || t_in.equals("Ship")){
            imageName = t_in + ".png";
            try{
            URL myurl = this.getClass().getResource(imageName);
            image = ImageIO.read(myurl);
            //image = ImageIO.read( new File( imageName ));
        }
        catch(IOException e){
            //Main.echo("Image could not be loaded");
        }
        }
        else{
            Main.echo("You are loading an invalid image");
        }
        
    }


    @Override
    public void paint(Graphics g) {
            g.drawImage(image, position.getX(), position.getY(), this);
    }


    public void setVelocity(){
        
    }

    public int getVelocity(){
        return velocity;
    }

    public String getType(){
        return type;
    }

}
